<template>
    <div id="energy-chart" :style="{width: '100%', height: curHeight}"></div>
</template>

<script>
import * as echarts from "echarts"

export default {
    props: ["height"],
    mounted() {
        this.initChart()
    },
    data() {
        return {
            curHeight: this.height + "px"
        }
    },
    methods: {
        initChart() {
            const chartDom = document.getElementById("energy-chart")
            const myChart = echarts.init(chartDom)
            const option = {
                title: {
                    text: "",
                    left: "50"
                },
                // subtitle: {
                // 	text: "综合能耗趋势分析",
                // 	left: "left",
                // },
                grid: {
                    left: "3%",
                    right: "2%",
                    bottom: "3%",
                    containLabel: true
                },
                toolbox: {
                    feature: {
                        print: {},
                        export: {}
                    },
                    right: 10
                },
                tooltip: {
                    trigger: "axis",
                    axisPointer: {
                        type: "shadow"
                    },
                    // formatter: "{a}{b} : {c}{d} 万"
                },
                xAxis: [
                    {
                        type: "category",
                        data: ["一卡通", "柜台", "支付宝", "微信", "银联"],
                        axisTick: {
                            alignWithLabel: true
                        }
                    }
                ],
                yAxis: [
                    {
                        type: "value",
                        name: "单位（万元）",
                        nameTextStyle: {
                            color: "#aaa",
                            nameLocation: "start"
                        }
                    }
                ],
                series: [
                    {
                        name: "金额",
                        type: "bar",
                        data: [120, 60, 20, 80, 15]
                    },
                    {
                        name: "趋势",
                        type: "line",
                        data: [10, 17, 14, 56, 5],
                        lineStyle: {
                            color: "orange"
                        }
                    }
                ]
            }
            myChart.setOption(option)
        }
    }
}
</script>

<style scoped>
/* 可根据需要添加样式 */
</style>
